﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UICheckBoxTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetCheckBoxState()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICheckBox checkBox = window.UICheckBox("@AutomationId='checkBox1'");
            Assert.AreEqual(ToggleState.Off, checkBox.ToggleState);
        }

        [TestMethod]
        public void ShouldSetUncheckedCheckBoxToChecked()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICheckBox checkBox = window.UICheckBox("@AutomationId='checkBox1'");
            Assert.AreEqual(ToggleState.Off, checkBox.ToggleState);
            checkBox.ToggleOn();
            Assert.AreEqual(ToggleState.On, checkBox.ToggleState);
        }

        [TestMethod]
        public void ShouldSetCheckedCheckBoxToUnchecked()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICheckBox checkBox = window.UICheckBox("@AutomationId='checkBox1'");
            checkBox.ToggleOn();
            Assert.AreEqual(ToggleState.On, checkBox.ToggleState);
            checkBox.ToggleOff();
            Assert.AreEqual(ToggleState.Off, checkBox.ToggleState);
        }

        [TestMethod]
        public void ShouldToggleCheckBox()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UICheckBox checkBox = window.UICheckBox("@AutomationId='checkBox1'");
            Assert.AreEqual(ToggleState.Off, checkBox.ToggleState);
            checkBox.Toggle();
            Assert.AreEqual(ToggleState.On, checkBox.ToggleState);
        }

        [TestMethod]
        public void ShouldGetAllCheckBoxes()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UICheckBox> checkBoxes = window.UICheckBoxes();
            Assert.AreEqual(7, checkBoxes.Count);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}